//
//  ViewController.m
//  26-Masonry
//
//  Created by dllo on 16/8/18.
//  Copyright © 2016年 ZHW. All rights reserved.
//

#import "ViewController.h"
#import "Masonry.h"
#import "CusTableViewCell.h"
@interface ViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *myTableView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Do any additional setup after loading the view, typically from a nib.

}

- (void)useMasonry {
    // 使用Masonry 不用给初始frame
    UIView *view = [[UIView alloc] init];
    view.backgroundColor = [UIColor redColor];
    // 添加约束前 需要把视图添加到父视图上
    [self.view addSubview:view];
    
    // 设置视图约束
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
        make.top.mas_equalTo(0);
    }];
    
    UIView *viewTwo = [UIView new];
    viewTwo.backgroundColor = [UIColor blueColor];
    [self.view addSubview:viewTwo];
    [viewTwo mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(100);
        make.centerX.mas_equalTo(0);
        make.centerY.mas_equalTo(0);
        make.width.mas_equalTo(self.view.mas_width).multipliedBy(0.5f);
        
    }];
    
    UIView *viewThree = [UIView new];
    viewThree.backgroundColor = [UIColor greenColor];
    [self.view addSubview:viewThree];
    [viewThree mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(viewTwo);
        make.height.mas_equalTo(viewTwo.mas_height);
        make.centerX.mas_equalTo(viewTwo);
        make.top.mas_equalTo(viewTwo.mas_bottom).offset(10);
        
    }];
    
    // viewThree.left = self.view.left * 1.0f + 0;
    [NSLayoutConstraint constraintWithItem:viewThree attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:viewTwo attribute:NSLayoutAttributeLeft multiplier:1 constant:0];
    [NSLayoutConstraint constraintWithItem:viewThree attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:viewTwo attribute:NSLayoutAttributeRight multiplier:1 constant:0];
    [NSLayoutConstraint constraintWithItem:viewThree attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:viewTwo attribute:NSLayoutAttributeHeight multiplier:1 constant:0];
    [NSLayoutConstraint constraintWithItem:viewThree attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:viewTwo attribute:NSLayoutAttributeCenterY multiplier:1 constant:10];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 5;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *ID = @"reuse";
    CusTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell = [[CusTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
